﻿<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>模块管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../static/css/font.css">
		<link rel="stylesheet" href="../../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

    <body>
        
        <div class="weadmin-nav">
            <span class="layui-breadcrumb" style="visibility: visible;">
                <a href="#">首页</a><span lay-separator="">/</span>
                <a href="#">基础数据设置</a><span lay-separator="">/</span>
                <a><cite>模块管理</cite></a>
            </span>
            <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i>
            </a>
        </div>
        <div class="weadmin-body">
            <table class="layui-hide" id="memberList" lay-filter="memberList"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
                </div>
            </script>
            <script id="barDemo" type="text/html">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>
        <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
        <script>
            layui.use(['table', 'laydate', 'jquery', 'layer'], function () {
                var table = layui.table,
                    laydate = layui.laydate,
                    $ = layui.jquery,
                    layer = layui.layer;
                //执行一个laydate实例
                laydate.render({
                    elem: '#start',
                    trigger: 'click'
                });
                //执行一个laydate实例
                laydate.render({
                    elem: '#end',
                    trigger: 'click'
                });
                $.support.cors = true;
                $.ajaxSetup({
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                })
                function showList(data) {
                    table.render({
                        elem: '#memberList',
                        cellMinWidth: 80,
                        toolbar: "#toolbar",
                        cols: [
                            [{
                                type: 'checkbox'
                            }, {
                                field: 'ModID', title: '模块编号', sort: true
                            }, {
                                field: 'ModName', title: '模块名字'
                            }, {
                                field: 'ModDesc', title: '模块描述'
                            }, {
                                field: 'ModURL', title: '模块地址'
                            }, {
                                field: 'ModParentID', title: '模块父级ID'
                            }, {
                                field: 'ModLevel', title: '模块级别'
                            },
                            { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 },
                            ]
                        ],
                        data: data,
                        event: true,
                        page: true
                    });
                }
                //头工具栏事件
                table.on('toolbar(memberList)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'delAll':
                            console.log(checkStatus.data);
                            break;
                        case 'add':
                            var add = layer.open({
                                type: 2,
                                title: "模块信息添加",
                                area: ['700px', '450px'],
                                fixed: false, //不固定
                                maxmin: true,
                                content: './module_add.html',
                                end: function () {
                                    location.reload();
                                }
                            });
                            layer.full(add);
                            break;
                    };
                });
                //监听行工具事件
                table.on('tool(memberList)', function (obj) {
                    var data = obj.data;
                    //console.log(obj)
                    if (obj.event === 'del') {
                        layer.confirm('确认删除行吗?', function (index) {
                            var postdata = { "ModID": data.ModID };
                            $.post(ApiUrl + 'Module/Del', postdata, function (data) {
                                if (data.StatusCode == 200) {
                                    obj.del();
                                    layer.msg(data.Info);
                                } else {
                                    layer.msg(data.Info);
                                }
                            });
                            //obj.del();
                            layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                        var edit = layer.open({
                            type: 2,
                            title: "人员信息编辑",
                            area: ['700px', '450px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: './module_edit.html?ModID=' + obj.data.ModID + "&ModName=" + obj.data.ModName + "&ModDesc=" + obj.data.ModDesc + "&ModParentID=" + obj.data.ModParentID + "&ModURL=" + obj.data.ModURL + "&ModLevel=" + obj.data.ModLevel,
                            end: function () {
                                location.reload();
                            }
                        });
                        layer.full(edit);
                    }
                });
                $(function () {
                    var postdata = { "swhere": "", "startindex": "1", "endindex": "100" }
                    $.post(ApiUrl + 'Module/Sel', postdata, function (data) {
                        if (data == null)
                            return '提交错误'
                        if (data.StatusCode == 200) {
                            showList(data.Data);
                        } else {
                            return data.Info;
                        }
                    });
                })
            });
        </script>

    </body>

</html>